/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.systemcar.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author danilo
 */
@Entity
@Table(name = "posto_combustivel")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PostoCombustivel.findAll", query = "SELECT p FROM PostoCombustivel p"),
    @NamedQuery(name = "PostoCombustivel.findByIdPosto", query = "SELECT p FROM PostoCombustivel p WHERE p.postoCombustivelPK.idPosto = :idPosto"),
    @NamedQuery(name = "PostoCombustivel.findByIdCombustivel", query = "SELECT p FROM PostoCombustivel p WHERE p.postoCombustivelPK.idCombustivel = :idCombustivel"),
    @NamedQuery(name = "PostoCombustivel.findByPrecoCombustivel", query = "SELECT p FROM PostoCombustivel p WHERE p.precoCombustivel = :precoCombustivel")})
public class PostoCombustivel implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PostoCombustivelPK postoCombustivelPK;
    @Basic(optional = false)
   // @NotNull
    @Column(name = "preco_combustivel", nullable = false)
    private double precoCombustivel;
    @JoinColumn(name = "id_combustivel", referencedColumnName = "cmb_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Combustivel combustivel;
    @JoinColumn(name = "id_posto", referencedColumnName = "pst_id", insertable = false, updatable = false)
    @ManyToOne(cascade= CascadeType.PERSIST)
    private Posto posto;

    public PostoCombustivel() {
    }

    public PostoCombustivel(PostoCombustivelPK postoCombustivelPK) {
        this.postoCombustivelPK = postoCombustivelPK;
    }

    public PostoCombustivel(PostoCombustivelPK postoCombustivelPK, double precoCombustivel) {
        this.postoCombustivelPK = postoCombustivelPK;
        this.precoCombustivel = precoCombustivel;
    }

    public PostoCombustivel(int idPosto, int idCombustivel) {
        this.postoCombustivelPK = new PostoCombustivelPK(idPosto, idCombustivel);
    }

    public PostoCombustivelPK getPostoCombustivelPK() {
        return postoCombustivelPK;
    }

    public void setPostoCombustivelPK(PostoCombustivelPK postoCombustivelPK) {
        this.postoCombustivelPK = postoCombustivelPK;
    }

    public double getPrecoCombustivel() {
        return precoCombustivel;
    }

    public void setPrecoCombustivel(double precoCombustivel) {
        this.precoCombustivel = precoCombustivel;
    }

    public Combustivel getCombustivel() {
        return combustivel;
    }

    public void setCombustivel(Combustivel combustivel) {
        this.combustivel = combustivel;
    }

    public Posto getPosto() {
        return posto;
    }

    public void setPosto(Posto posto) {
        this.posto = posto;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (postoCombustivelPK != null ? postoCombustivelPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PostoCombustivel)) {
            return false;
        }
        PostoCombustivel other = (PostoCombustivel) object;
        if ((this.postoCombustivelPK == null && other.postoCombustivelPK != null) || (this.postoCombustivelPK != null && !this.postoCombustivelPK.equals(other.postoCombustivelPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.systemcar.model.PostoCombustivel[ postoCombustivelPK=" + postoCombustivelPK + " ]";
    }
    
}
